import { useState, useEffect, useRef } from "react";

const Counter = () => {
    const [count, setCount] = useState(0);
    const timer = useRef(null);
    useEffect(() => {
        timer.current = setInterval(() => {
            setCount((count) => count + 1);
        }, 1000);
        return () => {
            clearInterval(timer.current);
        };
    }, []);
    return (
        <>
            <div className='alert alert-danger'>当前数据为：{count}</div>
        </>
    );
};

export default Counter;
